<template>
  <!-- 系统自动生成 -->
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="120px"
    >
      <el-form-item label="应用名称" prop="appName">
        <el-input
          v-model="queryParams.appName"
          placeholder="请输入应用名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="越权信息分类" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请输入越权信息分类"
          clearable
        >
          <el-option
            v-for="dict in dict.type.combat_apk_risk_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="应用分类" prop="appType">
        <el-input
          v-model="queryParams.appType"
          placeholder="请输入应用分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="app的简介" prop="appSummary">
        <el-input v-model="queryParams.appSummary" placeholder="请输入app的简介" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="app开发者" prop="appDeveloper">
        <el-input v-model="queryParams.appDeveloper" placeholder="请输入app开发者" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="app运营者" prop="appOperator">
        <el-input v-model="queryParams.appOperator" placeholder="请输入app运营者" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="app备案号" prop="appRecordno">
        <el-input v-model="queryParams.appRecordno" placeholder="请输入app备案号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="app主办者" prop="appSponsor">
        <el-input v-model="queryParams.appSponsor" placeholder="请输入app主办者" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="app更新时间" prop="appUpdatedate">
        <el-date-picker clearable v-model="queryParams.appUpdatedate" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择app更新时间">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="app版本号" prop="appVersion">
        <el-input v-model="queryParams.appVersion" placeholder="请输入app版本号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="app权限" prop="appAuthority">
        <el-input v-model="queryParams.appAuthority" placeholder="请输入app权限" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="app隐私政策" prop="appPrivacy">
        <el-input v-model="queryParams.appPrivacy" placeholder="请输入app隐私政策" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:application:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:application:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:application:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:application:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-row>
      <el-col :span="19">
        <el-table
      v-loading="loading"
      :data="applicationList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="app名称" align="center" prop="appName" />
      <!-- <el-table-column
        label="包名"
        align="center"
        prop="appPkgname"
      ></el-table-column> -->
      <el-table-column label="app版本号" align="center" prop="appVersion" />
      <el-table-column label="app分类" align="center" prop="appType" />
      <el-table-column label="评分" align="center" prop="appScore" />
      <el-table-column label="下载量" align="center" prop="appCountDownloads" />
      <el-table-column label="运行商" align="center" prop="appOperator" />
      <el-table-column label="数据来源" align="center" prop="sourceType" >
        <template slot-scope="scope">
          <span>{{ scope.row.sourceType == 1 ? '应用宝' : '上传' }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column
        label="app创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="越权信息类别"
        align="center"
        prop="type"
        width="180"
      >
        <template slot-scope="scope">
          <el-tag
            v-for="item in scope.row.type ? scope.row.type.split(',') : ''"
            :key="item"
            type="success"
            >{{ item }}</el-tag
          >
        </template>
      </el-table-column>
      <!-- appSummary -->
      <el-table-column label="简介" align="center" prop="appSummary">
        <template slot-scope="scope"> 
          <el-tooltip class="item" effect="dark" :content="scope.row.appSummary" placement="top">
            <span class="two-line-text">{{ scope.row.appSummary }}</span>
          </el-tooltip>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:application:edit']">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetail(scope.row)"
            >详情</el-button>
          <el-button
            size="mini"
            type="text"
            style="color: red;"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:application:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
      </el-col>
      <el-col :span="5">
        <div style="height: 400px;width: 100%;">
          <riskChart style="width: 100%;height: 100%;"  />
        </div>
      </el-col>
    </el-row>


    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="app名称" prop="appName">
              <el-input v-model="form.appName" placeholder="请输入app名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="app版本号" prop="appVersion">
              <el-input v-model="form.appVersion" placeholder="请输入app版本号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="app开发者" prop="appDeveloper">
              <el-input v-model="form.appDeveloper" placeholder="请输入app开发者" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="app运营者" prop="appOperator">
              <el-input v-model="form.appOperator" placeholder="请输入app运营者" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="app备案号" prop="appRecordno">
              <el-input v-model="form.appRecordno" placeholder="请输入app备案号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="app主办者" prop="appSponsor">
              <el-input v-model="form.appSponsor" placeholder="请输入app主办者" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="app更新时间" prop="appUpdatedate">
              <el-date-picker clearable
                v-model="form.appUpdatedate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择app更新时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="app权限" prop="appAuthority">
              <el-input v-model="form.appAuthority" placeholder="请输入app权限" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="app评分" prop="appScore">
              <el-input v-model="form.appScore" placeholder="请输入app评分" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="app下载次数" prop="appCountDownloads">
              <el-input v-model="form.appCountDownloads" placeholder="请输入app下载次数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="app包名" prop="appPkgname">
              <el-input v-model="form.appPkgname" placeholder="请输入app包名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="app分类" prop="appType">
              <el-input v-model="form.appType" placeholder="请输入app分类" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="app的md5值" prop="appMd5">
              <el-input v-model="form.appMd5" placeholder="请输入app的md5值" />
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-row>
          <!-- <el-col :span="12">
            <el-form-item label="app的sha-256哈希值" prop="appSha256">
              <el-input v-model="form.appSha256" placeholder="请输入app的sha-256哈希值" />
            </el-form-item>
          </el-col> -->
         
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="app的简介" prop="appSummary">
              <el-input v-model="form.appSummary" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="24">
            <el-form-item label="app隐私政策" prop="appPrivacy">
              <el-input v-model="form.appPrivacy" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row> -->
        <!-- <el-row>
          <el-col :span="24">
            <el-form-item label="app存放路径" prop="appPath">
              <el-input v-model="form.appPath" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row> -->
        <!-- <el-row>
          <el-col :span="24">
            <el-form-item label="app图标base64" prop="appIcon">
              <el-input v-model="form.appIcon" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listApplication,
  getApplication,
  delApplication,
  addApplication,
  updateApplication,
} from "@/api/crossSpacesystem/application";
import riskChart from './echartsDom.vue'

export default {
  name: "Application",
  components: {
    riskChart
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      applicationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        appName: null,
        appSummary: null,
        appDeveloper: null,
        appOperator: null,
        appRecordno: null,
        appSponsor: null,
        appUpdatedate: null,
        appVersion: null,
        appAuthority: null,
        appPrivacy: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },

  dicts: ["combat_apk_risk_type"],

  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listApplication(this.queryParams).then((response) => {
        this.applicationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        appid: null,
        appName: null,
        appSummary: null,
        appDeveloper: null,
        appOperator: null,
        appRecordno: null,
        appSponsor: null,
        appUpdatedate: null,
        appVersion: null,
        appAuthority: null,
        appPrivacy: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.appid);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const appid = row.appid || this.ids;
      getApplication(appid).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      console.log('row', row);
      this.$router.push({ path: '/applicationService/apk/detail', query: { id: row.appid } });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.appid != null) {
            updateApplication(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApplication(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const appids = row.appid || this.ids;
      this.$modal
        .confirm(
          '是否确认删除编号为"' + appids + '"的数据项？'
        )
        .then(function () {
          return delApplication(appids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "combat/application/export",
        {
          ...this.queryParams,
        },
        `application_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped>
.two-line-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
  max-height: 3em;
}
</style>
